package com.guijie.sheji.controller;

import com.guijie.sheji.common.MessageConstant;
import com.guijie.sheji.common.Result;
import com.guijie.sheji.common.StatusCode;
import com.guijie.sheji.domain.Login;
import com.guijie.sheji.domain.User;
import com.guijie.sheji.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @RequestMapping("/index")
    public Result login(@RequestBody Login loginUser) {
        System.out.println("收到登陆请求:" + loginUser.toString());
        Boolean userDb = loginService.selectByLoginName(loginUser);

        if (userDb) {
            System.out.println("登陆成功");
            return new Result(true, StatusCode.OK, MessageConstant.Login_SUCCESS, userDb);
        } else {
            System.out.println("登陆失败");
            return new Result(false, StatusCode.ERROR, MessageConstant.Login_FAILURE, userDb);
        }
    }


}


